package com.czg.redisdemo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class NewController {

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable Integer id, Model model){
        //阅读数+1
        Long read = redisTemplate.opsForHash().increment("new_" + id, "read", 1);
        //new_id这个对象里的所有属性一次性查出
        Map map = redisTemplate.opsForHash().entries("new_" + id);
        model.addAttribute(map);

        return "new1";
    }
}
